Skip to content

reject characters not allowed in XML in xpath_literal - #228

Open
itecz26 wants to merge 3 commits into
scrapy:masterfrom
itecz26:xpath-literal-non-xml-chars
Open

itecz26 wants to merge 3 commits into
scrapy:masterfrom
itecz26:xpath-literal-non-xml-chars

Conversation

@itecz26

@itecz26 itecz26 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

escapes like \1 (or a raw U+000B in a string) decode to characters XML doesn't allow and xpath_literal() copied them straight into the XPath, so css_to_xpath() returned something lxml refuses to compile with a ValueError (the strict xfail in test_escape_translates_non_xml); raising ExpressionError there instead keeps callers that rely on except SelectorError working, and since no document can contain those characters nothing that could match is lost.

@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (51b82b9) to head (2b3d10f).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #228   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines         1034      1037    +3     
  Branches       174       175    +1     
=========================================
+ Hits          1034      1037    +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@AdrianAtZyte

Copy link
Copy Markdown
Contributor

I wonder if the new assertions would fit better in their own test, since they are about translation rather than input preprocessing.

@itecz26

itecz26 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

agreed, they're about translation, not preprocessing. moved them into a separate test_non_xml_characters, so test_input_preprocessing is back to just the NUL/surrogate folding.

@AdrianAtZyte AdrianAtZyte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, rename has_non_xml_char to _has_non_xml_char, users do not need it.

@itecz26

itecz26 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

makes sense, renamed it to _has_non_xml_char. it was only used by xpath_literal() anyway.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants